<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <%layout("/WEB-INF/view/common/inc/admin_head.html",{title:'资源添加', styles:'bootstrap,font-awesome,animate,style,dtvalidate,layer,layui,bootstrap-table'}){%>
    <style type="text/css">
        body{padding-top:10px;}
        .hiddenDetailInfo{display:none;}
    </style>
    <%}%>
</head>
<body class="gray-bg">
<div class="wrapper wrapper-content animated fadeInRight">
    <input type="hidden" id="performanceStatus" name="performanceStatus" value="${performance.performanceStatus}">
    <input type="hidden" id="type" name="type" value="${type}">
    <div class="row">
        <div class="col-sm-12">
            <div class="ibox float-e-margins">
                <div class="ibox-title">
                    <h5>绩效考核目标设定</h5>
                </div>
                <div class="ibox-content">
                    <p>基本信息：</p>
                    <ul>
                        <li>${user.userRealname}</li>
                        <li>${powerGroup.groupName}</li>
                        <li>${performanceDate}</li>
                    </ul>

                    </p>
                </div>
            </div>
        </div>
    </div>
    <div class="row"  >
        <div class="col-sm-12" >
            <div class="ibox float-e-margins">
                <div class="ibox-title">
                    <h5>关键绩效指标KPI</h5>
                </div>

                <div class="ibox-content">

                    <!-- START 数据表格 -->
                    <table id="kpiTable"
                           data-toolbar="#toolbar"
                           data-side-pagination="server"
                           data-pagination="true"
                           data-resizable="true"
                           data-url="/sea/human/performanceDetail/findKPIByPerformanceId.do?performanceId=${performanceId}&flag=0"
                           data-page-size="15"
                           class="table table-striped table-hover"
                    >
                    </table>
                </div>
            </div>
        </div>
    </div>

    <div class="row">
        <div class="col-sm-12">
            <div class="ibox float-e-margins">
                <div class="ibox-title">
                    <h5>关键绩效指标OKR</h5>
                </div>
                <div class="ibox-content">
                    <!-- START 数据表格 -->
                    <table id="okrTable"
                           data-toolbar="#toolbar"
                           data-side-pagination="server"
                           data-pagination="true"
                           data-resizable="true"
                           data-url="/sea/human/performanceDetail/findOKRByPerformanceId.do?performanceId=${performanceId}&flag=1"
                           data-page-size="15"
                           class="table table-striped table-hover"
                    >
                    </table>
                </div>
            </div>
        </div>
    </div>
    <div class="row">
        <div class="col-sm-12">
            <div class="ibox float-e-margins">
                <div class="ibox-title">
                    <h5>企业文化</h5>
                </div>
                <div class="ibox-content">
                    <!-- START 数据表格 -->
                    <table id="cultureTable"
                           data-toolbar="#toolbar"
                           data-side-pagination="server"
                           data-pagination="true"
                           data-resizable="true"
                           data-url="/sea/human/performanceDetail/findCultureByPerformanceId.do?performanceId=${performanceId}&flag=2"
                           data-page-size="15"
                           class="table table-striped table-hover"
                    >
                    </table>
                </div>
            </div>
        </div>
    </div>
    <div class="row grade">
        <div class="col-sm-12">
            <div class="ibox float-e-margins">
                <div class="ibox-title">
                    <h5>评级</h5>
                </div>
                <div class="ibox-content">
                    <div class="form-group">
                        <div class="col-sm-12">
                            <select class="form-control m-b" id="performanceLevel" name="performanceLevel">
                                <option value="">请选择</option>
                                <option value="A">A</option>
                                <option value="B">B</option>
                                <option value="C">C</option>
                                <option value="D">D</option>
                            </select>
                        </div>
                    </div>

                </div>
            </div>
        </div>
    </div>
    <div class="hr-line-dashed"></div>
    <div class="form-group">
        <div class="col-sm-6 col-sm-offset-5">
            <button class="btn btn-primary submit-btn" >提交</button>
            <button class="btn btn-danger return-btn" >返回</button>
        </div>
    </div>
</div>



<div id="layer_window" style="display: none;overflow-x: hidden;overflow-y: hidden">
    <!-- START 内容部分 -->
    <div class="container" >
        <form class="form-horizontal" id="info-form" method="post" autocomplete="off" style="margin: auto">
            <input type="hidden" id="id" name="id" class="id">
            <input type="hidden" id="performanceId" name="performanceId" value="${performance.id}">
            <div class="form-group" style="margin-top: 20px">
                <label class="control-label col-sm-2" style="max-width: 100px">自评分</label>
                <div class="col-sm-6" style="max-width: 300px">
                    <input type="text" id="performanceSelfGrade" name="performanceSelfGrade" value="" onkeyup="value=value.replace(/[^\d\.]/g,'')" class="form-control">
                </div>
            </div>
            <div class="form-group" style="margin-top: 20px">
                <label class="control-label col-sm-2" style="max-width: 100px">自评原因</label>
                <div class="col-sm-6" style="max-width: 300px">
                    <textarea id="performanceSelfGradeReason" name="performanceSelfGradeReason" class="form-control"  rows="3"></textarea>
                </div>
            </div>
            <div class="form-group" style="margin-top: 20px">
                <label class="control-label col-sm-7" style="max-width: 100px"></label>
                <button type="button" class="save-btn btn btn-primary">
                    <i class="fa fa-save"></i> 保存
                </button>
            </div>
        </form>
    </div>
    <!-- END 内容部分 -->
</div>
<!-- END 内容部分 -->

<div id="layer_grade_window" style="display: none;overflow-x: hidden;overflow-y: hidden">
    <!-- START 内容部分 -->
    <div class="container" >
        <form class="form-horizontal" id="info-grade-form" method="post" autocomplete="off" style="margin: auto">
            <input type="hidden" name="id" class="id">
            <input type="hidden" class="performanceId" name="performanceId" value="${performance.id}">
            <div class="form-group" style="margin-top: 20px">
                <label class="control-label col-sm-2" style="max-width: 100px">评分</label>
                <div class="col-sm-6" style="max-width: 300px">
                    <input type="text" id="performanceGrade" name="performanceGrade" value="" onkeyup="value=value.replace(/[^\d\.]/g,'')" class="form-control">
                </div>
            </div>
            <div class="form-group" style="margin-top: 20px">
                <label class="control-label col-sm-7" style="max-width: 100px"></label>
                <button type="button" class="save-grade-btn btn btn-primary">
                    <i class="fa fa-save"></i> 保存
                </button>
            </div>
        </form>
    </div>
    <!-- END 内容部分 -->
</div>
<!-- START 公共脚本 -->
<%layout("/WEB-INF/view/common/inc/admin_js.html",{modules:'jquery,bootstrap,bootstrap-table,dtvalidate,dtvalidate-lang-zh_cn,laydate,layer,chosen,chosen-demo'}){}%>
<!-- END 公共脚本 -->
<script>
    var $kpiTable = $('#kpiTable');
    var $okrTable=$("#okrTable");
    var $cultureTable=$("#cultureTable");
    var index;
    var index2;
    var performanceStatus=$("#performanceStatus").val();
    var type=$("#type").val();
    $(function(){

        if(performanceStatus==2 || performanceStatus==1 || type==1){
            $(".submit-btn").hide();
            $(".grade").hide();
        }
        //START 表格配置
        $okrTable.bootstrapTable({
            paginationDetailHAlign:' hiddenDetailInfo',
            columns: [
                {
                    title: '绩效目标',
                    field: 'performanceTask',
                    align: 'center',
                    valign: 'middle'
                },
                {
                    title: '目标值',
                    field: 'performanceTarget',
                    align: 'center',
                    valign: 'middle'
                },

                {
                    title: '权重',
                    field: 'performanceWeight',
                    align: 'center',
                    valign: 'middle'
                },
                {
                    title: '考核办法',
                    field: 'performanceCheck',
                    align: 'center',
                    valign: 'middle'
                },
                {
                    title: '数据来源',
                    field: 'performanceSource',
                    align: 'center',
                    valign: 'middle'
                },
                {
                    title: '自评分',
                    field: 'performanceSelfGrade',
                    align: 'center',
                    valign: 'middle'
                },
                {
                    title: '自评原因',
                    field: 'performanceSelfGradeReason',
                    align: 'center',
                    valign: 'middle'
                },
                {
                    title: '上级评分',
                    field: 'performanceGrade',
                    align: 'center',
                    valign: 'middle'
                },
                {
                    field:  'operate',
                    title:  '操作',
                    align:  'center',
                    valign: 'middle',
                    formatter: optFormatter2
                }
            ],
            onLoadSuccess : function(){
                //新增
                $('.edit-okr-btn').on('click',function (){
                    $(".layui-layer-shade").remove();
                    $("#id").val($(this).attr("data-val"));
                    index=layer.open({
                        type:1,
                        title:'确认日期',
                        area:['600px','350px'],
                        skin:'layui-layer-lan',//layui-layer-molv ;layui-layer-lan;layui-layer-rim;layer-window
                        shadeClose:false,
                        resize: false,
                        scrollbar: false,
                        maxmin: false,//出现最大化按钮
                        content:$('#layer_window')
                    })
                })

                $('.grade-okr-btn').on('click',function (){

                    $(".id").val($(this).attr("data-val"));
                    index2=layer.open({
                        type:1,
                        title:'评分',
                        area:['600px','350px'],
                        skin:'layui-layer-lan',//layui-layer-molv ;layui-layer-lan;layui-layer-rim;layer-window
                        shadeClose:false,
                        content:$('#layer_grade_window')
                    })
                })
            },end:function(){
                $(".layui-layer-shade").remove();
            }
        });




        //START 表格配置
        $kpiTable.bootstrapTable({
            paginationDetailHAlign:' hiddenDetailInfo',
            columns: [
                {
                    title: '绩效目标',
                    field: 'performanceTask',
                    align: 'center',
                    valign: 'middle'
                },
                {
                    title: '目标值',
                    field: 'performanceTarget',
                    align: 'center',
                    valign: 'middle'
                },
                {
                    title: '指标计算公式',
                    field: 'performanceDefine',
                    align: 'center',
                    valign: 'middle'
                },
                {
                    title: '权重',
                    field: 'performanceWeight',
                    align: 'center',
                    valign: 'middle'
                },
                {
                    title: '考核办法',
                    field: 'performanceCheck',
                    align: 'center',
                    valign: 'middle'
                },
                {
                    title: '数据来源',
                    field: 'performanceSource',
                    align: 'center',
                    valign: 'middle'
                },
                {
                    title: '自评分',
                    field: 'performanceSelfGrade',
                    align: 'center',
                    valign: 'middle'
                },
                {
                    title: '自评原因',
                    field: 'performanceSelfGradeReason',
                    align: 'center',
                    valign: 'middle'
                },
                {
                    title: '上级评分',
                    field: 'performanceGrade',
                    align: 'center',
                    valign: 'middle'
                },
                {
                    field:  'operate',
                    title:  '操作',
                    align:  'center',
                    valign: 'middle',
                    formatter: optFormatter
                }
            ],
            onLoadSuccess : function(){
                $('.edit-kpi-btn').on('click',function (){
                    $(".layui-layer-shade").remove();
                    $("#id").val($(this).attr("data-val"));

                    index=layer.open({
                        type:1,
                        title:'自评',
                        area:['600px','350px'],
                        skin:'layui-layer-lan',//layui-layer-molv ;layui-layer-lan;layui-layer-rim;layer-window
                        content:$('#layer_window')
                    })

                })
                $('.grade-kpi-btn').on('click',function (){

                    $(".id").val($(this).attr("data-val"));
                    index2=layer.open({
                        type:1,
                        title:'评分',
                        area:['600px','350px'],
                        skin:'layui-layer-lan',//layui-layer-molv ;layui-layer-lan;layui-layer-rim;layer-window
                        shadeClose:false,
                        content:$('#layer_grade_window')
                    })
                })
            },end:function(){
                $(".layui-layer-shade").remove();
            }
        });


        //START 表格配置
        $cultureTable.bootstrapTable({
            paginationDetailHAlign:' hiddenDetailInfo',
            columns: [
                {
                    title: '绩效目标',
                    field: 'performanceTask',
                    align: 'center',
                    valign: 'middle'
                },
                {
                    title: '权重',
                    field: 'performanceWeight',
                    align: 'center',
                    valign: 'middle'
                },
                {
                    title: '考核办法',
                    field: 'performanceCheck',
                    align: 'center',
                    valign: 'middle'
                },
                {
                    title: '数据来源',
                    field: 'performanceSource',
                    align: 'center',
                    valign: 'middle'
                },
                {
                    title: '自评分',
                    field: 'performanceSelfGrade',
                    align: 'center',
                    valign: 'middle'
                },
                {
                    title: '自评原因',
                    field: 'performanceSelfGradeReason',
                    align: 'center',
                    valign: 'middle'
                },
                {
                    title: '上级评分',
                    field: 'performanceGrade',
                    align: 'center',
                    valign: 'middle'
                },
                {
                    field:  'operate',
                    title:  '操作',
                    align:  'center',
                    valign: 'middle',
                    formatter: optFormatter3
                }
            ],
            onLoadSuccess : function(){
                $('.edit-culture-btn').on('click',function (){
                    $(".layui-layer-shade").remove();
                    $("#id").val($(this).attr("data-val"));
                    index=layer.open({
                        type:1,
                        title:'自评',
                        area:['600px','350px'],
                        skin:'layui-layer-lan',//layui-layer-molv ;layui-layer-lan;layui-layer-rim;layer-window
                        shadeClose:false,
                        resize: false,
                        scrollbar: false,
                        maxmin: false,//出现最大化按钮
                        content:$('#layer_window')
                    })

                })
                $('.grade-culture-btn').on('click',function (){
                    $(".layui-layer-shade").remove();
                    $(".id").val($(this).attr("data-val"));
                    index2=layer.open({
                        type:1,
                        title:'评分',
                        area:['600px','350px'],
                        skin:'layui-layer-lan',//layui-layer-molv ;layui-layer-lan;layui-layer-rim;layer-window
                        shadeClose:false,
                        resize: false,
                        scrollbar: false,
                        maxmin: false,//出现最大化按钮
                        content:$('#layer_grade_window')
                    })
                })
            },end:function(){
                $(".layui-layer-shade").remove();
            }
        });

    });

    //操作菜单
    function optFormatter(value,row){
        var status=$("#performanceStatus").val();
        var content ='';
        if(status==2) {
            content += '<button class="edit-kpi-btn btn btn-xs btn-info" data-val="' + row.id + '" title="修改"><i class="fa fa-edit"></i> 自评</button>';
        }
        if(status==3 || status==31){
            content += '<button class="grade-kpi-btn btn btn-xs btn-info" data-val="' + row.id + '" title="修改"><i class="fa fa-edit"></i> 评分</button>';
        }
        return content;
    }

    //操作菜单
    function optFormatter2(value,row){

        var status=$("#performanceStatus").val();
        var content ='';
        if(status==2) {
            content += '<button class="edit-okr-btn btn btn-xs btn-info" data-val="' + row.id + '" title="修改"><i class="fa fa-edit"></i> 自评</button>';
        }
        if(status==3 || status==31){
            content += '<button class="grade-okr-btn btn btn-xs btn-info" data-val="' + row.id + '" title="修改"><i class="fa fa-edit"></i> 评分</button>';
        }
        return content;
    }

    //操作菜单
    function optFormatter3(value,row){
        var status=$("#performanceStatus").val();
        var content ='';
        if(status==2) {
            content += '<button class="edit-culture-btn btn btn-xs btn-info" data-val="' + row.id + '" title="修改"><i class="fa fa-edit"></i> 自评</button>';
        }
        if(status==3 || status==31){
            content += '<button class="grade-culture-btn btn btn-xs btn-info" data-val="' + row.id + '" title="修改"><i class="fa fa-edit"></i> 评分</button>';
        }
        return content;
    }

    $('.return-btn').on('click',function(){
        parent.layer.close(parent.layer.getFrameIndex(window.name)); //关闭弹窗
    });

    $('.save-btn').on('click',function(){
        //数据提交
        $.post('/sea/human/performanceDetail/usave.do',$('#info-form').serialize(),function(data){
            if( data.ok ){
                parent.layer.msg(data.msg,{icon:1,time:1500,shade: [0.8, '#393D49']}, function(){
                    $okrTable.bootstrapTable('refresh');
                    $kpiTable.bootstrapTable('refresh');
                    $cultureTable.bootstrapTable('refresh');
                    parent.$relatedTable.bootstrapTable('refresh');
                    clear();
                    layer.close(index); //关闭弹窗
                });
            }else{
                layer.msg(data.msg,{icon: 0,time:1500,shade: [0.8, '#393D49']});
            }
        });
    });
    $('.save-grade-btn').on('click',function(){
        //数据提交
        $.post('/sea/human/performanceDetail/usave.do',$('#info-grade-form').serialize(),function(data){
            if( data.ok ){
                parent.layer.msg(data.msg,{icon:1,time:1500,shade: [0.8, '#393D49']}, function(){
                    $okrTable.bootstrapTable('refresh');
                    $kpiTable.bootstrapTable('refresh');
                    $cultureTable.bootstrapTable('refresh');
                    parent.$relatedTable.bootstrapTable('refresh');
                    clear();
                    layer.close(index2); //关闭弹窗
                });
            }else{
                layer.msg(data.msg,{icon: 0,time:1500,shade: [0.8, '#393D49']});
            }
        });
    });

    $('.submit-btn').on('click',function(){
        var performanceLevel=$("#performanceLevel").val();
        if(performanceLevel==''){
            parent.layer.msg('请选择评级信息！',{icon: 0,time:1500,shade: [0.8, '#393D49']});
            return;
        }
        //数据提交
        $.post('/sea/human/performance/check.do',{id:$("#performanceId").val(),performanceStatus:6,performanceLevel:performanceLevel},function(data){
            if( data.ok ){
                parent.layer.msg(data.msg,{icon:1,time:1500,shade: [0.8, '#393D49']}, function(){
                    $okrTable.bootstrapTable('refresh');
                    $kpiTable.bootstrapTable('refresh');
                    $cultureTable.bootstrapTable('refresh');
                    parent.$relatedTable.bootstrapTable('refresh');
                    parent.layer.close(parent.layer.getFrameIndex(window.name)); //关闭弹窗
                });
            }else{
                layer.msg(data.msg,{icon: 0,time:1500,shade: [0.8, '#393D49']});
            }
        });
    });

    function clear(){
        $("#performanceSelfGradeReason").val("");
        $("#performanceSelfGrade").val("");
        $("#performanceGrade").val("");
    }

</script>
</body>
</html>